package com.rdc.qingkou.ui;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.Button;

import com.rdc.qingkou.Application.MyApplication;
import com.rdc.qingkou.R;
import com.rdc.qingkou.base.BaseActivity;
import com.rdc.qingkou.contract.PlayContract;
import com.rdc.qingkou.presenter.PlayPresenter;
import com.rdc.qingkou.widget.PlayButton;




public class PlayDialogActivity extends BaseActivity<PlayPresenter> implements PlayContract.View, View.OnClickListener {
    private PlayButton mPlay;
    private Button mCancel;
    private Button mConfirm;
    private String mAudioPath;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        MyApplication.addActivity(this);
        setContentView(R.layout.send_play);
        // StatusBarCompat.setStatusBarColor(this,getResources().getColor(R.color.windowBackground),true);

        init();
    }

    private void init(){
        mPlay = (PlayButton)findViewById(R.id.btn_play);
        mConfirm = (Button)findViewById(R.id.btn_confirm);
        mCancel = (Button)findViewById(R.id.btn_back);

        mPlay.setOnClickListener(this);
        mCancel.setOnClickListener(this);
        mConfirm.setOnClickListener(this);

        Intent intent = getIntent();
        mAudioPath = intent.getStringExtra("FilePath");
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.btn_play:
                mPresenter.play();
                break;
            case R.id.btn_back: {
                mPresenter.stop();
                mAudioPath = "";
                Intent intent = new Intent();
                intent.putExtra("AudioFile", mAudioPath);
                setResult(RESULT_OK,intent);
                finish();
            }
                break;
            case R.id.btn_confirm: {
                mPresenter.stop();
                Intent intent = new Intent();
                intent.putExtra("AudioFile", mAudioPath);
                setResult(RESULT_OK,intent);
                finish();
            }
                break;
            default:
                break;
        }
    }

    @Override
    public PlayPresenter getInstance() {
        return new PlayPresenter();
    }

    @Override
    public String getPath() {
        return mAudioPath;
    }

    @Override
    public void setProgressBar(int time) {
        mPlay.setPercent(time);
    }

    @Override
    public void setRecord(String s) {
        mPlay.setText(s);
    }

    @Override
    public void onBackPressed() {
        mPresenter.stop();
        Intent intent = new Intent();
        intent.putExtra("AudioFile", mAudioPath);
        setResult(RESULT_OK,intent);
        finish();
    }
}
